package so.sao.shop.supplier.service.impl;

import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import so.sao.shop.supplier.dao.CheckingAccountCommodityDao;
import so.sao.shop.supplier.pojo.Result;
import so.sao.shop.supplier.pojo.input.CheckCommSearchInput;
import so.sao.shop.supplier.pojo.output.CheckingAccountCommodity;
import so.sao.shop.supplier.service.CheckingAccountCommodityService;
import so.sao.shop.supplier.util.DataCompare;
import so.sao.shop.supplier.util.PageTool;

import java.util.List;

/**
 * <p>Version: supplier V1.2.0 </p>
 * <p>Title: CheckingAccountCommodityServiceImpl</p>
 * <p>Description: 商品对账</p>
 *
 * @author: chensha
 * @Date: Created in 2017/11/22 10:41
 */
@Service
public class CheckingAccountCommodityServiceImpl implements CheckingAccountCommodityService {

    @Autowired
    private CheckingAccountCommodityDao checkingAccountCommodityDao;

    /**
     * 根据条件查询商品列表
     * @param checkCommSearchInput 入参对象
     * @return 分页返回商品列表
     */
    @Override
    public Result searchCommodities(CheckCommSearchInput checkCommSearchInput) {
        //起始时间不能大于终止时间
        String timeCheck = DataCompare.createAtCheck(checkCommSearchInput.getBeginPaymentTime(),checkCommSearchInput.getEndPaymentTime());
        if(StringUtils.isNotEmpty(timeCheck)){
            return Result.fail(timeCheck);
        }
        //查询字段去空
        if(StringUtils.isNotEmpty(checkCommSearchInput.getInputValue())){
            checkCommSearchInput.setInputValue(checkCommSearchInput.getInputValue().trim());
        }
        if(StringUtils.isNotEmpty(checkCommSearchInput.getStoreName())){
            checkCommSearchInput.setStoreName(checkCommSearchInput.getStoreName().trim());
        }

        //分页
        PageTool.startPage(checkCommSearchInput.getPageNum(),checkCommSearchInput.getPageSize());
        List<CheckingAccountCommodity> list = checkingAccountCommodityDao.findAll(checkCommSearchInput);
        PageInfo<CheckingAccountCommodity> pageInfo = new PageInfo<>(list);
        return Result.success("查询财务商品列表成功：",pageInfo);
    }
}
